/**
 * 
 */
package reco.db.validation;

import static org.apache.commons.lang.StringUtils.isBlank;
import reco.db.Constraint;
import reco.db.Domain;
import reco.db.Field;

/**
 * Validate that a String value is not blank.
 * 
 * @param <D>
 *            {@link Domain} of checked {@link Field}.
 */
public final class NotBlankConstraint extends Constraint<String> {

    /**
     * Creates a not blank constraint on a string field.
     * 
     * @param constraintField
     *            String field over which the constraint will be applied.
     */
    public NotBlankConstraint() {
        super("notBlank", "isBlank");
    }

    /**
     * Check if the string is not blank.
     * <p>
     * Examples of constraint behaviour:
     * 
     * <pre>
     * <code>
     * NotBlankConstraint constaint = ...
     * assert constraint.validateValue(null);
     * assert !constraint.validateValue("");
     * assert !constraint.validateValue(" ");
     * assert constraint.validateValue("bob");
     * assert constraint.validateValue("  bob  ");
     * </code>
     * </pre>
     * 
     * @return <code>true</code> if value is <code>null</code> or if it has at least one not blank char; <code>false</code> in other way.
     */
    @Override
    public boolean validate(String value) {
        if (value == null) {
            return true;
        }
        return !isBlank(value);
    }

    @Override
    public Object[] getErrorArguments() {
        return null;
    }

}
